package com.smzd.framework.system.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.smzd.core.dao.AbstractDao;
import com.smzd.core.mappers.IMapper;
import com.smzd.framework.system.domain.Meeting;
import com.smzd.framework.system.domain.User;
import com.smzd.framework.system.mappers.UserMapper;
import com.smzd.framework.utils.db.ORPage;

@Component
public class UserDao extends AbstractDao<User> {
    @Autowired
    private UserMapper mapper;

    @Override
    protected IMapper<User> getMapper() {
        return mapper;
    }

    public User getUserByName(String name) {
        return mapper.getUserByName(name);
    }

    public List<User> getAllOwners(int meetingId) {
        return mapper.getAllOwners(meetingId);
    }

    public List<User> getUsersByGroupId(Integer groupId) {
        return mapper.getUsersByGroupId(groupId);
    }

    public void updateUserOwner(User user) {
        mapper.updateUserOwner(user);
    }

    public void updatePassword(User user) {
        mapper.updatePassword(user);
    }

	public ORPage<Meeting, User> getUsersWithGroups(ORPage<Meeting, User> page) {
		preparePage(page);
		List<User> elems = mapper.getUsersWithGroups(page);
		page.setElems(elems);
		int total = mapper.getUsersCountWithGroups(page);
		page.setTotalCount(total);
		completePage(page);
		return page;
	}
}
